import request from '@/utils/request'
import { useTokenStore } from '@/stores/token.js'

//文章分类列表接口
export const articleCategoryListService = () => {
    //获取token
    const tokenStore = useTokenStore()
    /**
     * 请求头配置
     * 1.Authorization 是请求头名称
     * :tokenStore.token 是请求值
     * 在pinia中定义的响应式数据，不需要.value就可以直接使用
     * 也可以在直接配置请求拦截器
     */
    // return request.get('/article/category', { headers: { 'Authorization': tokenStore.token } })
    return request.get('/category')
}
//文章分类添加接口
export const articleCategoryAddService = (addCategoryData) => {
    return request.post('/category', addCategoryData)
}

//文章分类更新接口
export const articleCategoryUpdateService = (updateCategoryData) => {
    return request.put('/category', updateCategoryData)
}
//文章分类删除接口
export const articleCategoryDeleteService = (categoryId) => {
    return request.delete('/category?id=' + categoryId)
}
//文章列表接口
export const articleListService = (query) => {//query是一个对象，包含了请求参数
    return request.get('/article', { params: query })//params是axios的配置项，即键值对表示请求参数
}
//新增文章列表接口
export const articleListAddService = (articleData) => {
    return request.post('/article', articleData)
}
//更新文章列表接口
export const articleListUpdateService = (articleData) => {
    return request.put('/article', articleData)
}
//删除文章列表接口
export const articleListDeleteService = (articleId) => {
    return request.delete('/article?id=' + articleId)
}